function validateChangePswForm()
{
	var oldPassword = document.getElementById("oldPassword").value;
	var newPassword1 = document.getElementById("newPassword1").value;
	var newPassword2 = document.getElementById("newPassword2").value;
	
	document.getElementById("message").innerHTML = "";
	document.getElementById("oldPswMsg").innerHTML = "";
	document.getElementById("newPswMsg1").innerHTML = "";
	document.getElementById("newPswMsg2").innerHTML = "";
	
	if (oldPassword == "" || newPassword1 == "" || newPassword2 == "") {
		
		if (oldPassword == "")			
			document.getElementById("oldPswMsg").innerHTML = "Inserire la vecchia password";
		
		if (newPassword1 == "")			
			document.getElementById("newPswMsg1").innerHTML = "Inserire la nuova password";
		
		if (newPassword2 == "")			
			document.getElementById("newPswMsg2").innerHTML = "Confermare la nuova password";
		return;
	}
	
	if (newPassword1 != newPassword2) {
		document.getElementById("newPassword2").value = "";
		document.getElementById("message").innerHTML = "Confermare correttamente la nuova password";
		return;
	}
	
	if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
	{ 
		xmlhttp = new XMLHttpRequest();
	}
	else // code for IE6, IE5
	{ 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			$response = xmlhttp.responseText;
			var message = "";
			if (!strcmp($response, "ERR")) {
				message = "Impossibile cambiare la password. Errore nel database";				
			} else if (!strcmp($response, "KO")) {
				message = "Password errata";
			} else {
				message = "Password modificata con successo";
			}
			
			document.getElementById("message").innerHTML = message;
			resetForm();
		}
	}

	xmlhttp.open("POST", "php/ajax/change_password.php", true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("oldPassword=" + oldPassword + "&newPassword=" + newPassword1);
}

function resetForm() {
	document.getElementById("oldPassword").value = "";
	document.getElementById("newPassword1").value = "";
	document.getElementById("newPassword2").value = "";
	document.getElementById("oldPswMsg").innerHTML = "";
	document.getElementById("newPswMsg1").innerHTML = "";
	document.getElementById("newPswMsg2").innerHTML = "";
}